<script setup lang="ts">
import { ref } from 'vue';
import { ElTable } from 'element-plus';
import useRecipients from '@/hooks/outlook/createEmail';
import { useCounterStore } from '@/stores/counter';
const counterStore = useCounterStore();

const {
  importExcelData,
  createEmailData
} = useRecipients()
interface ExcelDataType {
  con: string
  country: string
  qty: number
  eu: string
  bat: string
  ph: string
  reci: string
}

const multipleTableRef = ref<InstanceType<typeof ElTable>>()
const multipleSelection = ref<ExcelDataType[]>([])
const toggleSelection = (rows?: ExcelDataType[]) => {
  if (rows) {
    rows.forEach((row) => {
      // TODO: improvement typing when refactor table
      // eslint-disable-next-line @typescript-eslint/ban-ts-comment
      // @ts-expect-error
      multipleTableRef.value!.toggleRowSelection(row, undefined)
    })
  } else {
    multipleTableRef.value!.clearSelection()
  }
}
const handleSelectionChange = (val: ExcelDataType[]) => {
  multipleSelection.value = val
}
</script>

<template>
  <div class="container" style="height: calc(100% - 70px);">
    <div class="loader" v-if="counterStore.flag">
      <h5>正在创建邮件，请稍后..{{ counterStore.mailCount }}</h5>
      <div class="box-1"> </div>

    </div>

    <div :class="{ 'overlay': counterStore.flag }">
      <el-card>
        <ul style="display: flex;  align-items: center;">
          <li>
            <el-popconfirm width="220" confirm-button-text="OK" cancel-button-text="No, Thanks" icon="InfoFilled"
              icon-color="#626AEF" title="导入数据会先清除原所有数据，请确认是否继续？" @confirm="importExcelData">
              <template #reference>
                <!-- <el-button type="primary">导入数据</el-button> -->
                <button class="voltage-button">导入数据</button>
              </template>
            </el-popconfirm>
          </li>
          <li style="margin: 0 30px;">
            <el-popconfirm width="220" confirm-button-text="OK" cancel-button-text="No, Thanks" icon="InfoFilled"
              icon-color="#626AEF" title="将要创建所选择合同号的邮件，请确认是否继续？" @confirm="createEmailData(multipleSelection)">
              <template #reference>

                <div class="voltage-button" style="width: 100px;height: 30px;">
                  <button style="width: 100%;height: 100%;font-size: small;">创建邮件</button>
                  <svg version="1.1" x="0px" y="0px" viewBox="0 0 234.6 61.3" preserveAspectRatio="none"
                    xml:space="preserve">

                    <filter id="glow">
                      <feGaussianBlur class="blur" result="coloredBlur" stdDeviation="2"></feGaussianBlur>
                      <feTurbulence type="fractalNoise" baseFrequency="0.075" numOctaves="3" result="turbulence">
                      </feTurbulence>
                      <feDisplacementMap in="SourceGraphic" in2="turbulence" scale="30" xChannelSelector="R"
                        yChannelSelector="G" result="displace"></feDisplacementMap>
                      <feMerge>
                        <feMergeNode in="coloredBlur"></feMergeNode>
                        <feMergeNode in="coloredBlur"></feMergeNode>
                        <feMergeNode in="coloredBlur"></feMergeNode>
                        <feMergeNode in="displace"></feMergeNode>
                        <feMergeNode in="SourceGraphic"></feMergeNode>
                      </feMerge>
                    </filter>
                    <path class="voltage line-1"
                      d="m216.3 51.2c-3.7 0-3.7-1.1-7.3-1.1-3.7 0-3.7 6.8-7.3 6.8-3.7 0-3.7-4.6-7.3-4.6-3.7 0-3.7 3.6-7.3 3.6-3.7 0-3.7-0.9-7.3-0.9-3.7 0-3.7-2.7-7.3-2.7-3.7 0-3.7 7.8-7.3 7.8-3.7 0-3.7-4.9-7.3-4.9-3.7 0-3.7-7.8-7.3-7.8-3.7 0-3.7-1.1-7.3-1.1-3.7 0-3.7 3.1-7.3 3.1-3.7 0-3.7 10.9-7.3 10.9-3.7 0-3.7-12.5-7.3-12.5-3.7 0-3.7 4.6-7.3 4.6-3.7 0-3.7 4.5-7.3 4.5-3.7 0-3.7 3.6-7.3 3.6-3.7 0-3.7-10-7.3-10-3.7 0-3.7-0.4-7.3-0.4-3.7 0-3.7 2.3-7.3 2.3-3.7 0-3.7 7.1-7.3 7.1-3.7 0-3.7-11.2-7.3-11.2-3.7 0-3.7 3.5-7.3 3.5-3.7 0-3.7 3.6-7.3 3.6-3.7 0-3.7-2.9-7.3-2.9-3.7 0-3.7 8.4-7.3 8.4-3.7 0-3.7-14.6-7.3-14.6-3.7 0-3.7 5.8-7.3 5.8-2.2 0-3.8-0.4-5.5-1.5-1.8-1.1-1.8-2.9-2.9-4.8-1-1.8 1.9-2.7 1.9-4.8 0-3.4-2.1-3.4-2.1-6.8s-9.9-3.4-9.9-6.8 8-3.4 8-6.8c0-2.2 2.1-2.4 3.1-4.2 1.1-1.8 0.2-3.9 2-5 1.8-1 3.1-7.9 5.3-7.9 3.7 0 3.7 0.9 7.3 0.9 3.7 0 3.7 6.7 7.3 6.7 3.7 0 3.7-1.8 7.3-1.8 3.7 0 3.7-0.6 7.3-0.6 3.7 0 3.7-7.8 7.3-7.8h7.3c3.7 0 3.7 4.7 7.3 4.7 3.7 0 3.7-1.1 7.3-1.1 3.7 0 3.7 11.6 7.3 11.6 3.7 0 3.7-2.6 7.3-2.6 3.7 0 3.7-12.9 7.3-12.9 3.7 0 3.7 10.9 7.3 10.9 3.7 0 3.7 1.3 7.3 1.3 3.7 0 3.7-8.7 7.3-8.7 3.7 0 3.7 11.5 7.3 11.5 3.7 0 3.7-1.4 7.3-1.4 3.7 0 3.7-2.6 7.3-2.6 3.7 0 3.7-5.8 7.3-5.8 3.7 0 3.7-1.3 7.3-1.3 3.7 0 3.7 6.6 7.3 6.6s3.7-9.3 7.3-9.3c3.7 0 3.7 0.2 7.3 0.2 3.7 0 3.7 8.5 7.3 8.5 3.7 0 3.7 0.2 7.3 0.2 3.7 0 3.7-1.5 7.3-1.5 3.7 0 3.7 1.6 7.3 1.6s3.7-5.1 7.3-5.1c2.2 0 0.6 9.6 2.4 10.7s4.1-2 5.1-0.1c1 1.8 10.3 2.2 10.3 4.3 0 3.4-10.7 3.4-10.7 6.8s1.2 3.4 1.2 6.8 1.9 3.4 1.9 6.8c0 2.2 7.2 7.7 6.2 9.5-1.1 1.8-12.3-6.5-14.1-5.5-1.7 0.9-0.1 6.2-2.2 6.2z"
                      fill="transparent" stroke="#fff"></path>
                    <path class="voltage line-2"
                      d="m216.3 52.1c-3 0-3-0.5-6-0.5s-3 3-6 3-3-2-6-2-3 1.6-6 1.6-3-0.4-6-0.4-3-1.2-6-1.2-3 3.4-6 3.4-3-2.2-6-2.2-3-3.4-6-3.4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-1.1z"
                      fill="transparent" stroke="#fff"></path>
                  </svg>
                  <div class="dots">
                    <div class="dot dot-1"></div>
                    <div class="dot dot-2"></div>
                    <div class="dot dot-3"></div>
                    <div class="dot dot-4"></div>
                    <div class="dot dot-5"></div>
                  </div>
                </div>
              </template>
            </el-popconfirm>
          </li>
          <li style="font-size: large;color: red;margin-left: 20%;">
            <span>合同总数: {{ counterStore.excelData_pinia.length }}</span>
          </li>
        </ul>



      </el-card>

      <el-card>
        <el-scrollbar style="height: calc(100% - 70px);"> <!-- 菜单滚动条 -->
          <el-table ref="multipleTableRef" :data="counterStore.excelData_pinia" style="width: 100%" height="700"
            @selection-change="handleSelectionChange">
            <el-table-column type="selection"></el-table-column>
            <el-table-column type="index" label="序号"></el-table-column>
            <el-table-column prop="con" label="合同号"></el-table-column>
            <el-table-column prop="country" label="国家"></el-table-column>
            <el-table-column prop="qty" label="数量"></el-table-column>
            <el-table-column prop="eu" label="是否欧盟"></el-table-column>
            <el-table-column prop="bat" label="是否含电池"></el-table-column>
            <el-table-column prop="ph" label="是否拍照"></el-table-column>
            <el-table-column prop="reci" label="收件人类型"></el-table-column>
          </el-table>
        </el-scrollbar>
      </el-card>
    </div>
  </div>
</template>

<style scoped lang="scss">
.container {
  position: relative;
  height: 100vh;
  /* 使用视口高度来使容器填满整个屏幕 */
  overflow: hidden;
  /* 防止内容滚动 */
}

.loader {
  display: flex;
  /* 使 .loader 成为 Flex 容器 */
  flex-direction: column;
  /* 设置主轴方向为垂直 */
  align-items: center;
  /* 水平居中 */
  justify-content: center;
  /* 垂直居中 */
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  /* 使用负边距来居中元素 */
  z-index: 100;

  /* 其他样式... */
  h5 {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #626AEF;
    z-index: 200;
  }

}

.overlay {
  pointer-events: none;
  /* 禁用鼠标事件 */
  z-index: 1;
  /* 确保这个层在 loader 之下 */
  /* 其他样式... */
}

.box-1 {
  position: relative;
  height: 450px;
  width: 450px;
  background-color: #FFFFFF;
  background-image: linear-gradient(135deg, #FFFFFF 0%, #6284FF 34%, #FF0000 100%);
  border-radius: 50%;
  animation: rotate 3s linear infinite;
  box-shadow: rgba(17, 17, 26, 0.1) 0px 1px 0px, rgba(17, 17, 26, 0.1) 0px 8px 24px, rgba(17, 17, 26, 0.1) 0px 16px 48px;
}

@keyframes rotate {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

.box-1::before {
  content: '';
  position: absolute;
  inset: 15px;
  background: #f5f5f5;
  border-radius: 50%;
  box-shadow: rgb(204, 219, 232) 3px 3px 6px 0px inset, rgba(255, 255, 255, 0.5) -3px -3px 6px 1px inset;
}

.loader span {
  text-align: center;
  position: absolute;
  top: 65px;
  left: 25px;
  color: black;
  font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
  letter-spacing: 2px;
  font-weight: 800;
  font-size: 1rem;
  animation: text-animate412 3s linear infinite;
}

@keyframes text-animate412 {

  10% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

// 导入数据按钮样式
.voltage-button {
  position: relative;
}

.voltage-button button {
  color: white;
  background: linear-gradient(90deg, #03a9f4, #f441a5, #03a9f4);
  ;
  border-radius: 5rem;
  border: 5px solid #5978F3;
  font-size: 1.2rem;
  line-height: 1em;
  letter-spacing: 0.075em;
  transition: background 0.3s;
}

.voltage-button button:hover {
  cursor: pointer;
  background: #0F1C53;
}

.voltage-button button:hover+svg,
.voltage-button button:hover+svg+.dots {
  opacity: 1;
}

.voltage-button svg {
  display: block;
  position: absolute;
  top: -0.75em;
  left: -0.25em;
  width: calc(100% + 0.5em);
  height: calc(100% + 1.5em);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s;
  transition-delay: 0.1s;
}

.voltage-button svg path {
  stroke-dasharray: 100;
  filter: url("#glow");
}

.voltage-button svg path.line-1 {
  stroke: #f6de8d;
  stroke-dashoffset: 0;
  animation: spark-1 3s linear infinite;
}

.voltage-button svg path.line-2 {
  stroke: #6bfeff;
  stroke-dashoffset: 500;
  animation: spark-2 3s linear infinite;
}

.voltage-button .dots {
  opacity: 0;
  transition: opacity 0.3s;
  transition-delay: 0.4s;
}

.voltage-button .dots .dot {
  width: 1rem;
  height: 1rem;
  background: white;
  border-radius: 100%;
  position: absolute;
  opacity: 0;
}

.voltage-button .dots .dot-1 {
  top: 0;
  left: 20%;
  animation: fly-up 3s linear infinite;
}

.voltage-button .dots .dot-2 {
  top: 0;
  left: 55%;
  animation: fly-up 3s linear infinite;
  animation-delay: 0.5s;
}

.voltage-button .dots .dot-3 {
  top: 0;
  left: 80%;
  animation: fly-up 3s linear infinite;
  animation-delay: 1s;
}

.voltage-button .dots .dot-4 {
  bottom: 0;
  left: 30%;
  animation: fly-down 3s linear infinite;
  animation-delay: 2.5s;
}

.voltage-button .dots .dot-5 {
  bottom: 0;
  left: 65%;
  animation: fly-down 3s linear infinite;
  animation-delay: 1.5s;
}

@keyframes spark-1 {
  to {
    stroke-dashoffset: -1000;
  }
}

@keyframes spark-2 {
  to {
    stroke-dashoffset: -500;
  }
}

@keyframes fly-up {
  0% {
    opacity: 0;
    transform: translateY(0) scale(0.2);
  }

  5% {
    opacity: 1;
    transform: translateY(-1.5rem) scale(0.4);
  }

  10%,
  100% {
    opacity: 0;
    transform: translateY(-3rem) scale(0.2);
  }
}

@keyframes fly-down {
  0% {
    opacity: 0;
    transform: translateY(0) scale(0.2);
  }

  5% {
    opacity: 1;
    transform: translateY(1.5rem) scale(0.4);
  }

  10%,
  100% {
    opacity: 0;
    transform: translateY(3rem) scale(0.2);
  }
}

// 创建邮件按钮样式
.voltage-button {
  text-decoration: none;
  position: relative;
  border: none;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  color: #fff;
  //   width: 9em;
  //   height: 3em;
  //   line-height: 2em;
  text-align: center;
  background: linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);
  background-size: 300%;
  border-radius: 30px;
  z-index: 1;
}

.voltage-button:hover {
  animation: ani 8s linear infinite;
  border: none;
}

@keyframes ani {
  0% {
    background-position: 0%;
  }

  100% {
    background-position: 400%;
  }
}

.voltage-button:before {
  content: "";
  position: absolute;
  top: -5px;
  left: -5px;
  right: -5px;
  bottom: -5px;
  z-index: -1;
  background: linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);
  background-size: 400%;
  border-radius: 35px;
  transition: 1s;
}

.voltage-button:hover::before {
  filter: blur(20px);
}

.voltage-button:active {
  background: linear-gradient(32deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);
}
</style>